package com.easysoft.framework.patent.service;

import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.patent.mapper.PatentMapperExtd;
import com.easysoft.framework.patent.model.PatentQuery;
import com.easysoft.framework.patent.model.PatentView;
import com.easysoft.framework.patent.model.SysPatent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service("service.PatentService")
public class PatentService {
    @Autowired
    @Qualifier("mapper.PatentMapperExtd")
    private PatentMapperExtd patentMapperExtd;

    @DataSource(DataSource.SLAVE)
    public List<PatentView> selectPatentByPage(Page page, PatentQuery query) {
        int maxRow = patentMapperExtd.selectCountPatent(query);
        if (maxRow == 0){
            return new ArrayList<PatentView>();
        }
        page.setMaxRow(maxRow);
        return patentMapperExtd.selectPatentByPage(page,query);
    }

    @DataSource(DataSource.SLAVE)
    public SysPatent selectByPrimaryKey(String id){
        return patentMapperExtd.selectByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int deleteSysPatent(String id) {
        return patentMapperExtd.deleteByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int updateSysPatents(SysPatent patent) {
        return patentMapperExtd.updateByPrimaryKeySelective(patent);
    }

    @DataSource(DataSource.MASTER)
    public int addSysPatent(SysPatent patent) {
        patent.setId(UUIDUtils.getUUID());
        patent.setCreateTime(new Date());
        return patentMapperExtd.insertSelective(patent);
    }
}
